import matplotlib.pyplot as plt
import json
import numpy as np

dict = {}

with open("record.txt", 'r') as f:
    dict = json.load(f)

train_record = dict['train']
val_record = dict['val']

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(12, 12))
line1 = ax1.plot(train_record['loss'], color='b', label="Training loss")
line2 = ax1.plot(val_record['loss'], color='r', label="validation loss")
ax1.set_xlabel('epoch')
ax1.set_ylabel('loss')
ax1.set_xticks(np.arange(1, len(train_record['loss']), 1))
# ax1.set_yticks(np.arange(0, 1, 0.1))
ax1.legend(loc='best')
line3 = ax2.plot(train_record['Acc1'], color='b', label="Training accuracy")
line4 = ax2.plot(val_record['Acc1'], color='r', label="Validation accuracy")
ax2.set_xticks(np.arange(1, len(train_record['loss']), 1))
ax2.set_xlabel('epoch')
ax2.set_ylabel('accuracy')
plt.legend(loc='lower right', shadow=True)
plt.tight_layout()
plt.savefig('record.jpg')
plt.show()